<%@ page contentType="text/html;charset=utf-8" %>
<%@ page import="java.util.Date" %>
<%@ page import="ut.data.User" %>
<%@ page import="ut.data.Profile" %>
<%@ page import="ut.data.Record" %>
<%@ page import="ut.res.Language" %>
<%@ page import="ut.util.DateTime" %>
<%
	if(request.getParameter("uid") == null){
		response.sendRedirect("/");
		return;
	}
		
	User member = null;
	try{
		member = User.getUser(Integer.parseInt(request.getParameter("uid")));
	}catch(NumberFormatException e){
		response.sendRedirect("/");
		return;
	}
	if(member == null){
		response.sendRedirect("/");
		return;
	}
	
	int view = 0;
	try{
		view = Integer.parseInt(request.getParameter("view"));
	}catch(NumberFormatException e){}
	
	User user = (User)session.getAttribute("user");
	if(user != null && member.id == user.id){
		response.sendRedirect("/account/user-info.jsp?view=" + view);
	}
	
	Profile profile = Profile.getProfile(member.id);
	Record record = Record.getRecord(member.id);
%>

<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>UT終極一翻！ | 使用者資訊－<%= member.name %></title>
	<link rel="stylesheet" type="text/css" href="/style.css" media="all" />
	<link rel="stylesheet" type="text/css" href="/css/user-info.css" media="all" />
	<script type="text/javascript" src="/js/Utility.js"></script>
	<script type="text/javascript" src="/js/Message.js"></script>
	<script type="text/javascript" src="/js/Ajax.js"></script>
	<script type="text/javascript" src="/js/Button.js"></script>
	<script type="text/javascript" src="/js/Account.js"></script>
	<script type="text/javascript" src="/script.js"></script>
</head>
<body onload="init();">
<%@ include file="/include/banner.jsp" %>
	<div class="content">
		<div class="title" style="margin-bottom:60px">使用者資訊－<%= member.name %></div>
<%
	if(view == 0){
%>
<!--基本資料-->
		<div class="profile block">
			<div>
				<span class="tab current">基本資料</span>
				<span class="tab blue"><a class='link-tab' href="/account/member-info.jsp?uid=<%= member.id %>&view=1">發案紀錄</a></span>
				<span class="tab green"><a class='link-tab' href="/account/member-info.jsp?uid=<%= member.id %>&view=2">譯者資料＆接案紀錄</a></span>
			</div>
			<div class="toolbar">
<%
	/* 傳送私人訊息
	if(user == null){
%>
				<span class="tool js"
					onclick="Message.show('msg-message-create-err', 400, '權限不足', '請先登入以使用此功能', Message.BUTTON_OK)">
					傳送訊息給<%= member.name %>
				</span>
<%
	}else if(user.verify == 0){
%>
				<span class="tool js"
					onclick="Message.show('msg-message-create-err', 400, '權限不足', '您必須經過信箱驗證才可使用此功能', Message.BUTTON_OK)">
					傳送訊息給<%= member.name %>
				</span>
<%
	}else{
%>
				<span class="tool js"
					onclick="Message.show('msg-message-create', 470, '傳送訊息', Account.MessageCreate.instance);Account.MessageCreate.setValue(<%= member.id %>, '<%= member.name %>');Account.MessageCreate.instance.content.focus();">
					傳送訊息給<%= member.name %>
				</span>
<%
	}*/
	if(user == null){
%>
				<span class="tool js" onclick="Account.addFavorite(<%= member.id %>, -1);">將此使用者加入至關注列表</span>
<%
	}else{
%>
				<span class="tool js" onclick="Account.addFavorite(<%= member.id %>);">將此使用者加入至關注列表</span>
<%
	}
%>
			</div>
			<div class="profile-content">
				<div class="profile-element">
					<div class="profile-element-left">名稱：</div>
					<div class="profile-element-right"><%= member.name %></div>
				</div>
				<div class="profile-element">
					<div class="profile-element-left">E-Mail：</div>
					<div class="profile-element-right">
<%
		if(member.verify == 0){
%>
						<span class="mark-red">
							<img src="/image/error.png" class="middle" width="16px" /> 未通過驗證
						</span>
<%
		}else{
%>
						<span class="mark-green">
							<img src="/image/ok.png" class="middle" width="16px" /> 已通過驗證
						</span>
<%
		}
%>
					</div>
				</div>
				<div class="profile-element">
					<div class="profile-element-left">手機：</div>
					<div class="profile-element-right">
<%
		if(member.verify != 2){
%>
						<span class="mark-red">
							<img src="/image/error.png" class="middle" width="16px" /> 未通過驗證
						</span>
<%
		}else{
%>
						<span class="mark-green">
							<img src="/image/ok.png" class="middle" width="16px" /> 已通過驗證
						</span>
<%
		}
%>
					</div>
				</div>
				<div class="profile-element">
					<div class="profile-element-left">註冊時間：</div>
					<div class="profile-element-right"><%= DateTime.toDateTime(member.joinTime) %></div>
				</div>
				<div class="profile-element">
					<div class="profile-element-left">最後登入時間：</div>
					<div class="profile-element-right"><%= DateTime.toDateTime(member.loginTime) %></div>
				</div>
				<div style="clear:both"></div>
			</div>
		</div>
<%
	}else if(view == 1){
%>
<!--發案者資料-->
		<div class="profile block">
			<div>
				<span class="tab"><a class='link-tab' href="/account/member-info.jsp?uid=<%= member.id %>&view=0">基本資料</a></span>
				<span class="tab blue current">發案紀錄</span>
				<span class="tab green"><a class='link-tab' href="/account/member-info.jsp?uid=<%= member.id %>&view=2">譯者資料＆接案紀錄</a></span>
			</div>
			<div class="toolbar blue">
				<a class="tool" href="/free-task/free-task-list-member.jsp?uid=<%= member.id %>&type=employer">免費發案列表</a>
			</div>
			<div class="profile-content">
				<div class="profile-element">
					<div class="profile-element-left">免費案件發案數：</div>
					<div class="profile-element-right"><%= record.freeTask %></div>
				</div>
				<br/><br/>
				<div class="profile-element">
					<div class="profile-element-left">付費案件發案數：</div>
					<div class="profile-element-right"><%= record.task %></div>
				</div>
				<div class="profile-element">
					<div class="profile-element-left">付費案件成功數：</div>
					<div class="profile-element-right"><%= record.taskSuccess %></div>
				</div>
				<div class="profile-element">
					<div class="profile-element-left">付費案件綜合評價：</div>
					<div class="profile-element-right">
<%
		if(record.taskScoreNumber == 0){
%>
						<img src="/image/star-0.png" class="image-middle" />
						<img src="/image/star-0.png" class="image-middle" />
						<img src="/image/star-0.png" class="image-middle" />
						<img src="/image/star-0.png" class="image-middle" />
						<img src="/image/star-0.png" class="image-middle" />
<%
		}else{
			double score = record.taskScore / record.taskScoreNumber;
			for(int i = 1; i <= 5; i++){
				if(score >= 1){
%>
						<img src="/image/star-2.png" class="image-middle" />
<%
				}else if(score <= 0){
%>
						<img src="/image/star-0.png" class="image-middle" />
<%
				}else{
%>
						<img src="/image/star-1.png" class="image-middle" />
<%
				}
				score--;
			}
		}
%>
						<span class="mark-green comment">（已有 <%= record.taskScoreNumber %> 人評價）</span>
					</div>
				</div>
				<div style="clear:both"></div>
			</div>
		</div>
<%
	}else{
%>
<!--譯者資料-->
		<div class="profile block">
			<div>
				<span class="tab"><a class='link-tab' href="/account/member-info.jsp?uid=<%= member.id %>&view=0">基本資料</a></span>
				<span class="tab blue"><a class='link-tab' href="/account/member-info.jsp?uid=<%= member.id %>&view=1">發案紀錄</a></span>
				<span class="tab green current">譯者資料＆接案紀錄</span>
			</div>
			<div class="toolbar green">
				<a class="tool" href="/free-task/free-task-list-member.jsp?uid=<%= member.id %>&type=translator">免費接案列表</a>
			</div>
			<div id="profile-content" class="profile-content">
<%
		if(profile == null){
%>
				此用戶尚未建立譯者資料。
			</div>
<%
		}else{
%>
				<div class="profile-element">
					<div class="profile-element-left">翻譯專長：</div>
					<div class="profile-element-right">
<%
			String specFromLang = "";
			String specToLang = "";
			Language fromLang = null;
			Language toLang = null;
			for(int i = 0; i < profile.specialties.length; i++){
				fromLang = Language.getLanguage(profile.specialties[i][0]);
				toLang = Language.getLanguage(profile.specialties[i][1]);
				out.println("<div>");
				out.println("自<span class='spec-lang mark-red'>" + fromLang.title + "</span>");
				out.println("翻譯至<span class='spec-lang mark-red'>" + toLang.title + "</span>");
				out.println("</div>");
				
				if(i != profile.specialties.length - 1){
					specFromLang += fromLang.id + "," + fromLang.title + ";";
					specToLang += toLang.id + "," + toLang.title + ";";
				}else{
					specFromLang += fromLang.id + "," + fromLang.title;
					specToLang += toLang.id + "," + toLang.title;
				}
			}
%>
					</div>
				</div>
				<br/><br/>
				<div class="profile-element">
					<div class="profile-element-left">免費案件翻譯數：</div>
					<div class="profile-element-right"><%= record.freeResponse %></div>
				</div>
				<div class="profile-element">
					<div class="profile-element-left">免費案件最佳翻譯數：</div>
					<div class="profile-element-right"><%= record.freeSuccess %></div>
				</div>
				<br/><br/>
				<div class="profile-element">
					<div class="profile-element-left">付費案件接案數：</div>
					<div class="profile-element-right"><%= record.response %></div>
				</div>
				<div class="profile-element">
					<div class="profile-element-left">付費案件成功數：</div>
					<div class="profile-element-right"><%= record.success %></div>
				</div>
				<div class="profile-element">
					<div class="profile-element-left">付費案件綜合評價：</div>
					<div class="profile-element-right">
<%
		if(record.scoreNumber == 0){
%>
						<img src="/image/star-0.png" class="image-middle" />
						<img src="/image/star-0.png" class="image-middle" />
						<img src="/image/star-0.png" class="image-middle" />
						<img src="/image/star-0.png" class="image-middle" />
						<img src="/image/star-0.png" class="image-middle" />
<%
		}else{
			double score = record.score / record.scoreNumber;
			for(int i = 1; i <= 5; i++){
				if(score >= 1){
%>
						<img src="/image/star-2.png" class="image-middle" />
<%
				}else if(score <= 0){
%>
						<img src="/image/star-0.png" class="image-middle" />
<%
				}else{
%>
						<img src="/image/star-1.png" class="image-middle" />
<%
				}
				score--;
			}
		}
%>
						<span class="mark-green comment">（已有 <%= record.scoreNumber %> 人評價）</span>
					</div>
				</div>
				<br/><br/>
				<div class="profile-element">
					<div class="profile-element-left">自我介紹：</div>
					<div class="profile-element-right"><%= profile.description %></div>
				</div>
				<div class="profile-element">
					<div class="profile-element-left">學歷：</div>
					<div class="profile-element-right"><%= profile.education %></div>
				</div>
				<div class="profile-element">
					<div class="profile-element-left">語言相關證照：</div>
					<div class="profile-element-right"><%= profile.certification %></div>
				</div>
				<div class="profile-element">
					<div class="profile-element-left">工作經歷：</div>
					<div class="profile-element-right"><%= profile.experience %></div>
				</div>
				<div style="clear:both"></div>
			</div>
<%
		}
%>
		</div>
<%
	}
%>
<%@ include file="/include/foot.jsp" %>
	</div>
</body>
</html>